#include <QtGui>

 #include "mainwindow.h"

 MainWindow::MainWindow()
 {
     QWidget *widget = new QWidget;
     setCentralWidget(widget);

     QWidget *topFiller = new QWidget;
     topFiller->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

     infoLabel = new QLabel(tr("<i>Choose a menu option, or right-click to "
                               "invoke a context menu</i>"));
     infoLabel->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
     infoLabel->setAlignment(Qt::AlignCenter);

     QWidget *bottomFiller = new QWidget;
     bottomFiller->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

     QVBoxLayout *layout = new QVBoxLayout;
     layout->setMargin(5);
     layout->addWidget(topFiller);

     layout->addWidget(infoLabel);
     glwidget = new GLWidget(this);
     layout->addWidget(glwidget);

     layout->addWidget(bottomFiller);
     widget->setLayout(layout);

     createActions();
     createMenus();

     QString message = tr("A context menu is available by right-clicking");
     statusBar()->showMessage(message);

     setWindowTitle(tr("ChessNet 3D"));
     setMinimumSize(320, 240);
     resize(640, 480);
 }

 void MainWindow::contextMenuEvent(QContextMenuEvent *event)
 {
     QMenu menu(this);
     menu.addAction(aboutAct);
     menu.addAction(aboutQtAct);
     menu.exec(event->globalPos());
 }

 void MainWindow::newGame()
 {
     infoLabel->setText(tr("Invoked <b>File|New Game</b>"));
 }

 void MainWindow::open()
 {
     infoLabel->setText(tr("Invoked <b>File|Open</b>"));
 }

 void MainWindow::save()
 {
     infoLabel->setText(tr("Invoked <b>File|Save</b>"));
 }

 void MainWindow::prefs()
 {
     infoLabel->setText(tr("Invoked <b>Options|Preferences</b>"));
 }

 void MainWindow::about()
 {
     infoLabel->setText(tr("Invoked <b>Help|About</b>"));
     QMessageBox::about(this, tr("About ChessNet 3D"),
             tr("<b>ChessNet 3D</b> is a university "
                "project to make a Qt/OpenGL Chess Game."));
 }

 void MainWindow::aboutQt()
 {
     infoLabel->setText(tr("Invoked <b>Help|About Qt</b>"));
 }



  void MainWindow::debug()
 {
 }


 void MainWindow::createActions()
 {
     newAct = new QAction(tr("&New"), this);
     newAct->setShortcut(tr("Ctrl+N"));
     newAct->setStatusTip(tr("Start a new game"));
     connect(newAct, SIGNAL(triggered()), this, SLOT(newGame()));

     openAct = new QAction(tr("&Open..."), this);
     openAct->setShortcut(tr("Ctrl+O"));
     openAct->setStatusTip(tr("Open an existing game"));
     connect(openAct, SIGNAL(triggered()), this, SLOT(open()));

     saveAct = new QAction(tr("&Save"), this);
     saveAct->setShortcut(tr("Ctrl+S"));
     saveAct->setStatusTip(tr("Save the game to disk"));
     connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));

     exitAct = new QAction(tr("E&xit"), this);
     exitAct->setShortcut(tr("Ctrl+Q"));
     exitAct->setStatusTip(tr("Exit the application"));
     connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));

     prefsAct = new QAction(tr("&Preferences"), this);
     prefsAct->setShortcut(tr("Ctrl+P"));
     prefsAct->setStatusTip(tr("Shows the preferences panel"));
     connect(prefsAct, SIGNAL(triggered()), this, SLOT(prefs()));

     aboutAct = new QAction(tr("&About"), this);
     aboutAct->setStatusTip(tr("Show the application's About box"));
     connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));

     aboutQtAct = new QAction(tr("About &Qt"), this);
     aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
     connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
     connect(aboutQtAct, SIGNAL(triggered()), this, SLOT(aboutQt()));


     debugAct = new QAction(tr("&Debug"), this);
     debugAct->setStatusTip(tr("Debugging"));
     connect(debugAct, SIGNAL(triggered()), this, SLOT(debug()));
 }

 void MainWindow::createMenus()
 {
     fileMenu = menuBar()->addMenu(tr("&File"));
     fileMenu->addAction(newAct);
     fileMenu->addAction(openAct);
     fileMenu->addAction(saveAct);
     fileMenu->addSeparator();
     fileMenu->addAction(debugAct);
     fileMenu->addSeparator();
     fileMenu->addAction(exitAct);

     optionsMenu = menuBar()->addMenu(tr("&Options"));
     optionsMenu->addAction(prefsAct);

     helpMenu = menuBar()->addMenu(tr("&Help"));
     helpMenu->addAction(aboutAct);
     helpMenu->addAction(aboutQtAct);
 }
